package 蓝桥真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class 贪吃蛇长度 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       static char[][]c=new char[100][100];
       static int idx=0;       
       public static void main(String[] args) throws IOException {
    	      br.read(c[idx++],0,51);
		      while(!"0".equals(br.readLine())){
		    	    br.read(c[idx++],0,51);
		      }
		      int res=0;
		      for(int i=0;i<idx;i++)
		    	  for(int j=0;j<51;j++){
		    		  if(c[i][j]=='H')res++;
		    		  else if(c[i][j]=='#')res++;
		    		  else if(c[i][j]=='@')res+=2;
		    		  else if(c[i][j]=='T')res++;
		    	  }
		      System.out.print(res);
	  }
}
